package com.enjoy;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("127.0.0.1", 10001);

        try (InputStream inputStream = socket.getInputStream(); OutputStream outputStream = socket.getOutputStream()) {
            outputStream.write("hello,server".getBytes());
            outputStream.flush();
            byte[] bytes = new byte[1024];
            Thread.sleep(1000);
            final int i = inputStream.read(bytes);
            if (i > 0) {
                System.out.println(new String(bytes));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
